d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Quick Question Regarding Wordpress Php Query > Permalink Stuff
12Next
Add Reply New Topic New Poll
Member
Posts: 9,202
Joined: Sep 22 2009
Gold: 18,819.66
Aug 9 2014 01:35pm
So basically this. All tutorials or help say I need to have something like

echo '<a class='front workitem' href=" '.the_permalink()' ">';

Which doesnt seem to work. The current one I have just pulls .the_permalink.
Im assuming I need to add something to my array and then hook it in, but I'm not the best with args and hooks more of a CSS guy.

Any help would be great.


Code

<?php
$args = array(
'posts-per-page' => 6,
'cat' => 2,
'order' => 'DESC'
);
query_posts( $args );
if (have_posts()) :
while (have_posts()) : the_post();
echo "<article class='pure-u-1-2'>";
echo "<a class='front workitem' href='.the_permalink()'>";
echo get_the_post_thumbnail();
echo "</a>";
echo "<a class='back workitem' href='.the_permalink()'>";
echo "<div class='tiletitle'>";
echo get_the_title();
echo "</div>";
echo "<span class='btn'>View Project</span>";
echo "</a>";
echo "</article>";
endwhile;
endif;
wp_reset_query();
?>
Member
Posts: 9,202
Joined: Sep 22 2009
Gold: 18,819.66
Aug 9 2014 07:38pm
echo "<a class='front workitem' href='.the_permalink()'>";

This isn't working btw

thats the problem.


so it pulls the link as ".the_permalink" and tries to go to blahblahbl.com/.the_permalink
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Aug 10 2014 08:18pm
Maybe it'd help if you ask a question
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Aug 10 2014 08:45pm
Code
echo '<a class="front workitem" href="'.the_permalink().'">';


or

Code
<a class="front workitem" href="<? echo the_parmalink(); ?>">
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Aug 10 2014 08:49pm
Code
$args = array(
'posts-per-page' => 6,
'cat' => 2,
'order' => 'DESC'
);
query_posts( $args );
if (have_posts()) :
while (have_posts()) : the_post();
?>
<article class="pure-u-1-2">
<a class="front workitem" href="<? echo the_permalink(); ?>"> <? echo get_the_post_thumbnail(); ?></a>
<a class="back workitem" href="<? echo the_permalink(); ?>">
<div class="tiletitle"><? echo get_the_title(); ?></div>
<span class="btn">View Project</span>
</a>
</article>
<?
endwhile;
endif;
wp_reset_query();
?>


something like that

This post was edited by SelfTaught on Aug 10 2014 08:51pm
Retired Moderator
Posts: 18,570
Joined: Feb 27 2004
Gold: 11,858.00
Trader: Trusted
Aug 11 2014 09:24am
Fairly certain you don't want to use echo with the_permalink() function. If he was using get_permalink() it'd be a different story.

I PM'd him some code the other day, curious as to whether or not it is working.

Code
<?php

$args = array(
'posts-per-page' => 6,
'cat' => 2,
'order' => 'DESC'
);

query_posts( $args );

if (have_posts()) :
while (have_posts()) : the_post();

$permalink = get_permalink();
$thumbnail = get_the_post_thumbnail();
$title = get_the_title();
$output = '';

$output .= "<article class='pure-u-1-2'>";
$output .= "<a class='front workitem' href='$permalink'>";
$output .= $thumbnail;
$output .= "</a>";
$output .= "<a class='back workitem' href='$permalink'>";
$output .= "<div class='titletitle'>";
$output .= $title;
$output .= "</div>";
$output .= "<span class='btn'>View Project</span>";
$output .= "</a>";
$output .= "</article>";

echo $output;

endwhile;
endif;

wp_reset_query();

?>


This post was edited by Blind[zF] on Aug 11 2014 09:25am
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Aug 11 2014 11:20am
Quote (Blind[zF&#93; @ Aug 11 2014 07:24am)
Fairly certain you don't want to use echo with the_permalink() function. If he was using get_permalink() it'd be a different story.

I PM'd him some code the other day, curious as to whether or not it is working.

Code
<?php

$args = array(
    'posts-per-page'    => 6,
    'cat'              => 2,
    'order'            => 'DESC'
);

query_posts( $args );

if (have_posts()) :
    while (have_posts()) : the_post();

        $permalink  = get_permalink();
        $thumbnail  = get_the_post_thumbnail();
        $title      = get_the_title();
        $output    = '';

        $output .= "<article class='pure-u-1-2'>";
            $output .= "<a class='front workitem' href='$permalink'>";
                $output .= $thumbnail;
            $output .= "</a>";
            $output .= "<a class='back workitem' href='$permalink'>";
                $output .= "<div class='titletitle'>";
                    $output .= $title;
                $output .= "</div>";
                $output .= "<span class='btn'>View Project</span>";
            $output .= "</a>";
        $output .= "</article>";

        echo $output;

    endwhile;
endif;

wp_reset_query();

?>


yep it looks like you're right B)

http://codex.wordpress.org/Function_Reference/the_permalink

my main intention was to show him 'correct' syntax for using html / php together.
Retired Moderator
Posts: 18,570
Joined: Feb 27 2004
Gold: 11,858.00
Trader: Trusted
Aug 11 2014 01:12pm
Quote (SelfTaught @ Aug 11 2014 12:20pm)
yep it looks like you're right  B)

http://codex.wordpress.org/Function_Reference/the_permalink

my main intention was to show him 'correct' syntax for using html / php together.


Oh yah, I understand. His concantation was off slightly.

I adjusted it to only call echo once as I was told that from a performance issue it is faster to do so. Same with not closing out the php tags and reopening it.

Though I've heard the other end of the argument with closing php tags when you're doing actual html.

So whatever, to each their own.
Member
Posts: 24,488
Joined: Jul 11 2011
Gold: 1,272.50
Aug 11 2014 04:17pm
That $output code is horrible, don't .= it all out, use one variable and echo.

And it's not working because you're missing a period (.) before the (').


This post was edited by HighschoolTurd on Aug 11 2014 04:19pm
Member
Posts: 9,202
Joined: Sep 22 2009
Gold: 18,819.66
Aug 12 2014 02:02pm
Quote (Blind[zF&#93; @ Aug 11 2014 11:24am)
Fairly certain you don't want to use echo with the_permalink() function. If he was using get_permalink() it'd be a different story.

I PM'd him some code the other day, curious as to whether or not it is working.




Works perfectly. Thanks for all the help guys. I wanted to read through all the comments and try to learn what I could from it as I've worked with hook snippets, but don't really code them from scratch much.


One more question though.

This is pulling 7 from the category even though this is in the array.

Any idea why its not working?

Code
'posts-per-page' => 6,

Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll