1 (edited by 2008-08-17 13:10:42)

Topic: [HACK] Have a "Sticky" Top Article

Name: "Sticky" Top Article
Author: EmoOnline
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: Ever wanted to have one news post or article above all of the rest? ... Well ... This code below is the static version (aka you need to update via files not through cutenews!)
note: simpler alternative available here: Having Pinned/Important posts
In the next topic we'll discuss how to have 1 specific article on a page.
Instructions:
This hack exists in changing the CN Inlcude code, no CuteNews files need to be edited.

<?PHP
   $sticky = $_SERVER["REQUEST_URI"];
   if($sticky == "/" or $sticky== "/index.php")
   {
   echo "Some Text here

";
   }
   /* And the following code is just the regular show news stuff. */
   $number = "5";
   include("cutenews/show_news.php");
   ?>

Ok the above shows "Some Text here" on your website and below this will show 5 news articles from your cutenews installation.  Once you click on "read more" or "comment" the "Some Text Here" text will disappear.  How does this work?

   $sticky = $_SERVER["REQUEST_URI"];
Checks the referral, which, should be your homepage... forget about this, its important so dont change it http://cutephp.com/forum/style_emoticons/default/tongue.gif

   if($sticky == "/" or $sticky== "/index.php")
This is the part you can choose to change.  The script gets the referral information from the line above.....checks it against your site and index.php (as above) and if your site has www.mysite.com/index.php or www.mysite.com then it will display the "some text here".

If your site is www.mysite.com/about.php it will not display "some text here" it is ONLY for the "RooT" of your website and the index.php page (which, you can change yourself).


<?PHP
   $sticky = $_SERVER["REQUEST_URI"];
   if($sticky == "/" or $sticky== "/index.php")
   {
$number="1";
$subaction="showfull";
$id="xxx"; // the id of the sticky article
$template="xxx";
$category="xxx";
include("news/show_news.php");
   }

   $number = "5";
   include("cutenews/show_news.php");
   ?>

Ok the above seems complicated....but lets break it down.....


$number="1";
shows one post....the sticky article

$subaction="showfull";
only for cutenews 1.x.x

$id="xxx";
The news id (very important) .... write a news article, add it, post it.....Now go to "edit news" and hover your mouse over the title or click on it...See the long number digit? .... its usually about 11 characters long (not hard to miss) . write that in place of the "xxx".

$template="xxx";
Make a template (if you want) and include it where the "xxx" is.

$category="xxx";
Make a category (if you want) and include it where the "xxx" is.

include("news/show_news.php");
The main include, essential.

With all the above correctly done, you can manage your new sticky topic through cutenews instead of it being static !! http://cutephp.com/forum/style_emoticons/default/smile.gif

Re: [HACK] Have a "Sticky" Top Article

ORIGINAL POST FOR MORE INFORMATION!!!


What the hack is:
This hack allows you to put "page-specific" data on a page that utilizes CuteNews  :blink:.  Let me elaborate:

Do you want to display something like an introduction to your site on your main page and then your CuteNews data below it?  In a normal scenario, your main site (for our purposes it will be called 'index.php', would look something like this:

<html>
<body>
  Hello World!  Welcome to my website, index.php!
  This is a really dumb intro, so to put you out of your misery,
  here is some news:
  


  <?php include("cutenewsdirectory/show_news.php"); ?>
  

  

  Thanks for reading my news!  Bye!
</body>
</html>


When you actually looked at that page in a browser, it would look something like:

index.php wrote:

Hello World!  Welcome to my website, index.php!  This is a really dumb intro, so to put you out of your misery, here is some news:


Babies overtake Germany
This just in.  It looks as though Germany has been over-run by a group of wild babies.  They appear to be showing no mercy, eating anything and everything in their path - leaving a trail of death and fecal matter in their wake.
Read More - Comments (1337)

-------------------

Missy Elliott is officially the coolest person in the world
God just declared Missy Elliott to be the coolest person in the world.  He was too tied up to comment - he muttered something about babies and Germany before shuffling off, but he made it very clear that Missy Elliott was the coolest person in the world.
Read More - Comments (666)

Thanks for reading my news!  Bye!

So far so good, right?  Right!  Until you click 'Read More'.  Let's click on it:

index.php?subaction=showfull&id=1103068371&archive=&start_from=&ucat=& wrote:

Hello World!  Welcome to my website, index.php!  This is a really dumb intro, so to put you out of your misery, here is some news:


Babies overtake Germany
This just in.  It looks as though Germany has been over-run by a group of wild babies.  They appear to be showing no mercy, eating anything and everything in their path - leaving a trail of death and fecal matter in their wake.  I suppose I should say more since this is the 'full article'.  Apparently the babies are heading towards the ocean where they have hired terrorists to build them small aircrafts so that they can traverse the globe, causing havoc everywhere.  They plan on utilizing chemical warfare from their aircrafts, dropping toxic material including dirty diapers, breastmilk, and urine.  Counties all around the world are trying to group all nannies so they can try to get these brutal babies under control.  Authorities are saying to flee if any babies flying aircrafts are near.  More updates to come.

comments:

#1337 - Poster #1 is an idiot.

[posters #2-#1336]

#1 - Wow babies are teh l33t babbzorrz, but whie dunt tey dr0p teh crunk juice!1!11!1

post your comment:
Name: |_________|
Website/Email: |___________|
Comment: |_______________|                       Remember Me? |/|
[Submit] [Clear]

Thanks for reading my news!  Bye!

As you can see - before the article starts, it says: "Hello World!  Welcome to my website, index.php!  This is a really dumb intro, so to put you out of your misery, here is some news:" when that should only be displayed on the main page, 'index.php'.

So that is what this hack does.  It lets you put something only on the main page.

How Does it Work?

You add this script to the main page, wherever you want to include the page-specific content.  What the script does is request the visitor's URL from the server, and then it checks whether the url is the main page or not.  If it is the main page then it displays the page-specific data.  If it is not the right page, then it just displays the news.

Okay, sounds good, but now I need the code.

Well, if you insist:

<?PHP
$urssss = $_SERVER["REQUEST_URI"];    /* This code requests the current URL of the visitor from the                                                        server and stores it in the variable $urssss.
                                          Feel free to change variable names. */

if($urssss == "/" or $urssss== "/index.php")   /* This code checks to see if the visitor is on the main
                                                  page.  If they are on the main page then it executes
                                                  the following code: */
    {
    echo "This is the page-specific content.  This can include HTML, so feel free to. [b]Welcome to my website![/b] [i]Blah blah blah blah blah[/i]";
    } ?>

So you paste that code wherever you want the page-specific content.

Let's apply that code to our example.

Hey, I was thinking the same thing!  Okay, our original example webpage would look like this with the hack in operation:

<html>
<body>
  <?PHP
    $urssss = $_SERVER["REQUEST_URI"];    /* This code requests the current URL of the visitor from the                                                        server and stores it in the variable $urssss.
                                          Feel free to change variable names. */

if($urssss == "/" or $urssss== "/index.php")   /* This code checks to see if the visitor is on the main
                                                  page.  If they are on the main page then it executes
                                                  the following code: */
    {
    echo "Hello World!  Welcome to my website, index.php!
  This is a really dumb intro, so to put you out of your misery,
  here is some news:";
    } ?>
  


  <?php include("cutenewsdirectory/show_news.php"); ?>
  

  


 if($urssss == "/" or $urssss== "/index.php")   /* This code checks to see if the visitor is on the main
                                                  page.  If they are on the main page then it executes
                                                  the following code: */
    {
    echo " Thanks for reading my news!  Bye!";
    } ?>
</body>
</html>

And that would make the text only appear on your home page, assuming your home page is index.php.  If it is not, then change the if statement to be:

 if($urssss == "/" or $urssss== "/whateveryourpageiscalled.php") 

Is there anywhere that I can see this hack being implemented?

Why, yes!  I didn't make it for no reason.  I am using it on my website, EmoOnline.com:

If you go to the main page and look, you will see that I have an introduction, saying what the site is about.

Then go to this example article and you will notice that there is no introduction in front of the article.

This hack could have a million different uses, so don't hesitate to use it.

If you have any questions, PM me. smile

EmoOnline

3 (edited by 2008-12-01 13:16:07)

Re: [HACK] Have a "Sticky" Top Article

Name: "Sticky" Top Article
Author: FUNimations
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: We'll discuss how to have 1 specific article on a page.
Instructions:
In the previous post the idea is to have other news as well that does not influence the 1 stickied.
But if you want just 1 specific article displayed on a page without using categories.
Something along the line of this should work better. And is easier to understand as less code is required then the example above.

$number="1";
if(!isset($_GET['subaction']) && !isset($_POST['subaction']))
$subaction="showfull";
$id="xxx"; // the id of the sticky article
$template="xxx";
$category="xxx";
$ucat = $category;
include("news/show_news.php");


the xxx's have the same value as in the previous post

$number="1";
shows one post....the sticky article

$subaction="showfull";
only for cutenews 1.x.x

$id="xxx";
The news id (very important) .... write a news article, add it, post it.....Now go to "edit news" and hover your mouse over the title or click on it...See the long number digit? .... its usually about 11 characters long (not hard to miss) . write that in place of the "xxx".

$template="xxx";

Make a template (if you want) and include it where the "xxx" is.

$category="xxx";
Make a category (if you want) and include it where the "xxx" is.

include("news/show_news.php");
The main include, essential.

if(!isset($_GET['subaction']) && !isset($_POST['subaction']))
this is the only code different from the above hack. This code is added in case want commenting on that article. As when you submit a comment, $subaction needs to be some other value.