Jump to content

Archived

This topic is now archived and is closed to further replies.

ketri

How can I hook something to a post (e.g. before or after title) on a loop?

Recommended Posts

ketri    7
ketri

Hi

I'm using Types -plugin to add a field where the site owner can upload a PDF to each post. 
On a category page I want to show the titles of the posts as links to these PDFs. The articles are only for pdfs, there is no content, exceprt, thumbnails etc. ever.

So I should probably use a hook to insert a link to the PDF on the archive pages. I've tried using

 


add_action('the_post', 'postFunction', 10);
    function postFunction() { 
      echo "<h1>pdf link here</h1>";
}

Just to get me started before I figure out the details of what to add. It now adds the code before the title on archive pages. But it also adds that code pretty much everywhere. https://www.dropbox.com/s/0p70s2h3sx0pjj0/Screenshot%202014-08-20%2010.07.31.png

 

So how can I use a hook to add something to category pages?
I'd also like to remove the title/link to the actual post, and the read more button.

Thank you!

 

 

Share this post


Link to post
Share on other sites
ketri    7
ketri

Another option would be to remove the loop from archive-pages and use  custom code a section (or even use NextBox?) to list the pdfs (custom fields) of all the posts in this category. 
I think this might be a better solution for this particular problem. 

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

Hi Ketri,

 

If you want to use a hook and have that hook only display on a category or archive page, you will need to use the WordPress functions below inside your hook.

 

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

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

 

However, if you want to only display certain information i.e. no content, feature images, excerpts etc... then you don't really need the WP-Content/PostLoop section. You will probably want to create your own section, that way you have much more control over the structure.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
ketri    7
ketri

Hi Ketri,

 

If you want to use a hook and have that hook only display on a category or archive page, you will need to use the WordPress functions below inside your hook.

 

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

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

 

However, if you want to only display certain information i.e. no content, feature images, excerpts etc... then you don't really need the WP-Content/PostLoop section. You will probably want to create your own section, that way you have much more control over the structure.

Thank you.

The problem with for example this code:

add_action('the_post', 'postFunction', 10);
    function postFunction() { 
      if(is_category()){
      echo "<h1>pdf link here</h1>";
      }
}

is that it loads it everywhere else outside the main loop, in the header, in the menu, in the sidebar etc.

Indeed a custom section seems smarter. I'll see if I can code one myself but it's possible that I'll need the basic structure for a custom section that works as a loop for an archive.

Share this post


Link to post
Share on other sites
ketri    7
ketri

Danny

Two questions.

1. I see there is  

pagelines_register_hook( 'pagelines_loop_before_excerpt', 'theloop' ); // Hook

Still when I try to use

add_action('the_loop', 'postFunction', 10);    function postFunction() { 
   
      echo "<h1>pdf link here</h1>";
}

or

add_action('pagelines_loop_after_excerpt', 'postFunction', 10);    function postFunction() { 
   
      echo "<h1>pdf link here</h1>";
}

It doesn't seem to work like 

 

add_action('the_post', 'postFunction', 10);
    function postFunction() { 
      echo "<h1>pdf link here</h1>";
}

does. 

Should I be able to use this hook? How should it work?

Second question:

If I have a blank custom section, what should I put in the 

 
function section_template() {}

to make it work like a category loop? 
The original postloop-section is so complex that I don't really understand how to use it. I know how to use loops and what to write inside if I can just get the barebone version of what this section should contain to loop posts from the category on which page it's on.

Thank you!

 

Share this post


Link to post
Share on other sites
ketri    7
ketri

If I just copy paste the standard loop in a custom section the whole site wont load:
 

<?php
/*
Section: KetriLoop
Author: PageLines
Author URI: http://www.pagelines.com
Description: The Main Content area (Post Loop in WP speak). Includes content and post information.
Class Name: ketriPostLoop
Workswith: main
Failswith: 404_page
Filter: component
*/


/**
 * Main Post Loop Section
 *
 * @package PageLines DMS
 * @author PageLines
 */
class ketriPostLoop extends PageLinesSection {


   function section_template() {
if (have_posts()) : while (have_posts()) : the_post(); ?>


<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
</div>


<?php endwhile; 
}


}

 

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

On your white screen what error is printed ? If no error is printed do you have WP_DEBUG set to true ?


Please search our forums, before posting!

Share this post


Link to post
Share on other sites

  • Similar Content

    • Grant Turck
      By Grant Turck+
      What file do I need to add code to in my pl-framework-pagelines child theme to insert script after opening body tag on every page?
      Can you someone provide me with the code also?
    • Michael Kummer
      By Michael Kummer+
      Hi guys,
      Is it possible, and if so, how, to change the layout of the archive pages? For example, I would like to use a smaller and more compact image size for featured images and shorten the amount of text that's displayed for each post without also changing how featured images are displayed on single post pages.
      I am talking about https://michaelkummer.com/apple/ vs How to extend the storage of your iPhone or iPad.
      Thanks
      Michael
       
    • Timothy
      By Timothy+
      Question! Does anyone know how to display a full post rather than the excerpt on the posts page? Normally I can replace 'the_excerpt' with 'the_content' on the page template, but i'm not finding that in the Framework templates...
      Thoughts?
    • micstepl
      By micstepl+
      When inserting a LOOP-Section within a WORDPRESS-Section (Pagelines Framework Content) >>> Images (loops_media) do not show. 
      (same section outside, works well)
    • micstepl
      By micstepl+
      how to make (easy) a post Navigation: previous / next
×