1

My Wordpress theme (Big Point) allows me to showcase a list of posts by category.

I have set the format of my posts with a 'documents' category to all be 'links' and when I choose the 'link' format the page displays a URL field which I populate with a link to a PDF.

When I visit the page in the front-end that lists the posts with the 'documents' category I want the href to point to the URL entered into the URL field rather than taking me to a single post page where I then have to click the link to access the file. I want to skipp the middle step.

On the content-single-link.php page the code that displays the link is as follows:

<?php $ptype_link_url = get_post_meta($post->ID, 'lolfmkbox_link_url', true); ?>
<h1 class="entry-title"><a href="<?php echo $ptype_link_url; ?>"><?php the_title(); ?></a></h1>
<?php lollum_header_posts($ptype_link_url); ?>

I'd like to utilize this code on my block-blog-list.php page. The code on this page that links to the single blog post page is:

<a class="news-link" href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'lollum'), the_title_attribute('echo=0')); ?>" rel="bookmark">
<?php $categories_list = get_the_category_list(' '); $cat = get_the_category(); ?>
<p class="entry-title news-title"><?php the_title(); ?></p> 
</a> 

How would I declare the variable $ptype_link_url on the block-blog-list.php page?

The function that loops through the records starts like this, defining some variables. I've added $ptype_link_url but it does not appear to register:

function lolfmk_print_blog_list($item) {
    $header_text = lolfmk_find_xml_value($item, 'header-text');
    $blog_type = lolfmk_find_xml_value($item, 'blog-type');
    $post_category = lolfmk_find_xml_value($item, 'post-category');
    $blog_number = lolfmk_find_xml_value($item, 'blog-number');
    $ptype_link_url = lolfmk_find_xml_value($item, 'lolfmkbox_link_url'); //***
    $p_image_url = lolfmk_find_xml_value($item, 'lolfmkbox_p_image_url');

And the loop starts as:

$post_query = new WP_Query($args);
$counternews = 0;
while($post_query->have_posts()) : $post_query->the_post(); $counternews++; ?>

I presume I need to use $post_query->the_post() to somehow get and declare the 'lolfmkbox_link_url' URL value. Assistance greatly appreciated.

migrated from stackoverflow.com Nov 24 '15 at 19:19

This question came from our site for professional and enthusiast programmers.

1

You don't have a $post object to use $post->ID, so use get_the_ID() instead. In your loop:

<?php $ptype_link_url = get_post_meta(get_the_ID(), 'lolfmkbox_link_url', true); ?>
<h1 class="entry-title"><a href="<?php echo $ptype_link_url; ?>"><?php the_title(); ?></a></h1>

Reference: https://codex.wordpress.org/Function_Reference/get_the_ID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.