← WordPress

[Addon] Link within style

Lida 6196 vezes

Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

Adicionem no functions.php do vosso tema (dentro de umas tags php:

Código: [Seleccione]
function get_first_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i’, $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Imagem default se não existir uma imagem no post
$first_img = “/images/default.jpg”;
}
return $first_img;
}

Adicionem no vosso single.php (ou onde quiserem):

Código: [Seleccione]
<h2>Conteúdo Aleatório</h2>
<div class="avossaclass">
<?php
    $conteudoaleatorio 
= new WP_Query();
    
$conteudoaleatorio ->query('showposts=4&orderby=rand');
    while (
$conteudoaleatorio ->have_posts()) : $conteudoaleatorio ->the_post();
?>


<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img alt="<?php the_title(); ?>" src="<?php echo get_first_image(); ?>" width="120" height="120" /></a>

<?php endwhile; ?></div>

Dicas para utilizarem este addon:

  • Dentro da class que criaram criem a propriedade "img" e costumizem com uma border, com algum padding ou uma margin.
  • Na propriedade showposts= podem definir a quantidade de posts que querem mostrar

Isto ainda está muito rudimentar, mas em breve irei desenvolver mais, se assim o quiserem :)

Se quiserem deixar um link para o videosloucos agradeço :lol:

Abraço ;)
Offline

raugusto 
Elite
Mensagens 3145 Gostos 33
Feedback +13

Troféus totais: 31
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

já fazias um plugin wordpress nao? mas obrigado por partilhares...
Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

Ainda estou a ler a documentação... :lol: Vou pedir uma ajuda ao orion mas depois disponibilizo dessa forma ;)
Offline

JoseOliveira 
Membro
Mensagens 526 Gostos 4
Troféus totais: 30
Trófeus: (Ver todos)
Linux User Mobile User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

já fazias um plugin wordpress nao?

Pois :)

Se fizeres um plugin e publicares no wordpress.org os links podem surgir de  modo natural como sabes ;)
Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

Hehe, não quero links nenhuns, coloquei isto aqui porque já tinha feito para mim ;) Isto é código vindo directamente do codex...
Offline

Pedro Lopes 
Beta tester
Mensagens 3568 Gostos 18
Feedback +6

Troféus totais: 32
Trófeus: (Ver todos)
Level 6 Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Amanha tento fazer o plugin, se o DiguiVirus deixar. :P
Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

Amanha tento fazer o plugin, se o DiguiVirus deixar. :P

Opah, deixa-me aprender, nunca fiz um plugin... Tenho de começar por algum lado! tu ajudas-me vá... :lol:
Offline

Pedro Lopes 
Beta tester
Mensagens 3568 Gostos 18
Feedback +6

Troféus totais: 32
Trófeus: (Ver todos)
Level 6 Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Ok. xD

Se precisares de algo diz no msn. ;)
Offline

raugusto 
Elite
Mensagens 3145 Gostos 33
Feedback +13

Troféus totais: 31
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

não queres links? tu é que me lixas...

então e se eu te pagar o plugin e ficar no meu site e os links vierem para mim?

Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

não queres links? tu é que me lixas...

Opah, claro que quero links :lol: O que quero dizer é que com a colocação aqui deste tópico o meu objectivo não foi, de todo, obter links ;)
Offline

bfms 
Equipa
Mensagens 1769 Gostos 40
Feedback +1

Troféus totais: 35
Trófeus: (Ver todos)
Search Level 6 Apple User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes Poll Voter Poll Starter

Estive a colocar agora no PDL, obrigado pela partilha do código, fica fixolas :)
Offline

raugusto 
Elite
Mensagens 3145 Gostos 33
Feedback +13

Troféus totais: 31
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

está perfeito no pdl...

obrigado diguivirus...
Offline

Pedro Lopes 
Beta tester
Mensagens 3568 Gostos 18
Feedback +6

Troféus totais: 32
Trófeus: (Ver todos)
Level 6 Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Para quando o plugin?

Senão faço eu com o código que uso nos meus blogs, se conseguir. :lol:
Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

Ainda bem que gostaram ;)

@ORiOn, já perdi mais de 12 horas à volta com isto e não consegui nada... estás à vontade...
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Ele vai buscar os relacionados através de quê?
Tags? Conteúdo? Título? :)