• Greetings,
    I need to add in the navigation menu links to archives of certain categories. I cannot link the category because it uses a modified template loop that is hiding some of the posts that have an expiration date set and I need them to appear in the archive pages.

    How can this be done? Or is there any way to load the category with different template based on the url (for example https://localhost/?cat=86&template=archive) I have very poor knowledge of php so please give me some advice.

    Thanks for your time.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You could just put code in your modified category.php file to check for $_GET[‘template’] == ‘archive’, and use the correct logic based on that.

    If you really need separate templates, you can use the approach below. Since I do not know if you have a special name for your modified category.php, the example assumes you did not rename it.

    Create category-archive.php to show the full category. Rename your modified category.php to category-modified.php. Save the file below to category.php.

    <?php
    // category-archive.php shows the full category
    // category-modified shows posts with expiration date
    
    if ( $_GET['template'] == 'archive' ) {
      include(TEMPLATEPATH . '/category-archive.php'); }
    else {
      include(TEMPLATEPATH . '/category-modified.php');
    }
    ?>
    Thread Starter Meduncho

    (@meduncho)

    Ok, but how can I link it in the menu? It will be the same category so the link would be like – https://localhost/?cat=86 for example, I’ll have the category “Anouncements” and I need a link named “Archive” that leads to the same category but loads the second template so the expired posts are shown ?

    Use the WP Menu builder with Custom Links and add the argument ‘template=archive’ to the proper item.

    Thread Starter Meduncho

    (@meduncho)

    Thanks a lot, that did the trick

    Thread Starter Meduncho

    (@meduncho)

    A small issue came up, when I go to the archive page and hit to go next page (second page of posts) it keeps repeating the posts on the second page endlessly, the entire loop is repeated one after another.
    What could be causing it, the link is https://localhost/?cat=35&template=archive&paged=2

    Loop code: `
    [Code moderated as per the Forum Rules. Please use the pastebin]

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Link to category archive’ is closed to new replies.