WordPress.org

Ready to get started?Download WordPress

Forums

How to: Customizing page2cat markup via a template (3 posts)

  1. One Crayon
    Member
    Posted 4 years ago #

    Strangely, the page2cat author embedded all the markup that the plugin outputs directly in the plugin, and I can't find a way to get into contact with him/her to share how to fix this, so here it is in the hopes other users can find it useful.

    This is the basic code snippet that will load a template named page2cat.php and use it to create the output of the page2cat_output() function:

    if (get_query_template('page2cat') != '') {
        load_template(get_query_template('page2cat'));
    }

    To add this to your copy of the plugin, update one of the switch cases in the page2cat_output function in the page2cat.php plugin file. For instance, if you wanted to have this used by default you could replace the 'getpost' case in the function (starts line 749) with this:

    case 'getpost':
    ?>
    <div id="category-page-header">
    <?php
    $post = $post_temp;
    $post = get_post($pageid);
    setup_postdata($post);
    
    if($post->post_title!=""){
        if (get_query_template('page2cat') != '') {
            load_template(get_query_template('page2cat'));
        } else {
                ?>
                <div id="p2c-header">
                    <h1><?php echo $post->post_title; ?></h1>
                    <?php the_content(); ?>
                </div>
            <div class="category-page-cleaner"></div>
    <?php
        }
    echo '</div>';
    $post = $post_temp;
    }
    break;

    An example template that would work would be a page in your theme called page2cat.php with the following contents:

    <div id="p2c-header">
        <h1><?php the_title(); ?></h1>
        <?php the_content(); ?>
    </div>

    Hopefully this helps others; I'd love to see all of the markup in the plugin removed and replaced with optional templates, but I can't find any good way to contact the developer.

    http://wordpress.org/extend/plugins/page2cat/

  2. One Crayon
    Member
    Posted 4 years ago #

    Further testing has revealed a couple limitations of the original code posted above, and this damn forum doesn't let me edit posts, so here's the corrections:

    General snippet:

    if (get_query_template('page2cat') != '') {
        include(get_query_template('page2cat'));
    }

    Plugin page2cat.php file:

    case 'getpost':
    ?>
    <div id="category-page-header">
    <?php
    $post = $post_temp;
    $post = get_post($pageid);
    setup_postdata($post);
    
    if($post->post_title!=""){
        if (get_query_template('page2cat') != '') {
            include(get_query_template('page2cat'));
        } else {
                ?>
                <div id="p2c-header">
                    <h1><?php echo $post->post_title; ?></h1>
                    <?php the_content(); ?>
                </div>
            <div class="category-page-cleaner"></div>
    <?php
        }
    echo '</div>';
    $post = $post_temp;
    }
    break;

    Theme page2cat.php file:

    <div id="p2c-header">
        <h1><?php echo $post->post_title; ?></h1>
        <?php the_content(); ?>
    </div>
  3. Pneumonic
    Member
    Posted 4 years ago #

    I think what you've done here is what I did here, but your code is much shorter. Although the way I re-wrote it, it gives the user the option to output the content via the admin panel.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags