• 0
Sign in to follow this  
Followers 0

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


Question

Posted · Report post

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

6 answers to this question

  • 0

Posted · Report post

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
  • 0

Posted · Report post

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.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0