0
votes

I have a script in place in my wordpress install which shows all the posts which reside under the custom post type 'publicnews'.

The outcome is great and displays all the posts I want to be displayed but the the list is not clickable.

I would like it so each post displayed in the output links to their permalink page.

Essentially what I am looking to do is, display all the posts which sit under the custom post type 'publicnews' in a list outside the loop. The posts which display should be clickable and lead to their full page.

Below is a view of the full code:

<!-- Dynamic News Box -->

<div class="col-md-8 col-sm-6">
    <div class="row">
        <div class="col-md-6">
            <div class="panel panel-template panel-color<?=$color?>">
                <div class="panel-body small-text newspagesmall">
                    <h3 class="h3_title">
                        <span class="icon-fleche"></span>
                        <a class="titre_href" href="">
                            NEWS BOX
                        </a>
                    </h3>
                    <div class="scrollablenews_div">
                        <ul>
                            <?php
                            query_posts( array( 'post_type' => 'publicnews', 'showposts' => 10 ) );
                            if ( have_posts() ) : while ( have_posts() ) : the_post();
                            ?>
                            <li><?php the_title(); ?></li>
                        <?php endwhile; endif; wp_reset_query(); ?>
                    </ul>
                </div>
            </div>

        </div>

    </div>

I hope you can help!

1
The code you have shared doesn't have anything to do with displaying the list, only querying for it. You're going to need to share some more of the code, in order for us to help you. Also, it's unclear what exactly should be clickable. - rnevius
Essentially what I am looking to do is, display all the posts which sit under the custom post type 'publicnews' in a list outside the loop. The posts which display should be clickable and lead to their full page. - Jake
That's great...but we still need to see your existing code. - rnevius
Let me try to explain it to you: <?php query_posts( array( 'post_type' => 'publicnews', 'showposts' => 10 ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> /* There Should Be Something Here */ <?php endwhile; endif; wp_reset_query(); ?> <-- look inside your code, where it should have some code outputting your supposed list. It's missing. Please, provide it. - al'ein
@AlanMachado , not quite. the_post() is a WordPress function which simply sets up post data. It's not responsible for content output. Which means that the above code alone cannot be responsible for outputting the list in the screenshot. - rnevius

1 Answers

1
votes

You just need to wrap your title in a proper permalink:

<li>
    <a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
    </a>
</li>

This is covered right in the WordPress Codex.